package wc;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class CountTest {

	String file1 = "D:\\soft-ware\\PersonalProject-Java\\201621123037qinyu\\WordCount_2\\test1.txt";
	String file2 = "D:\\soft-ware\\PersonalProject-Java\\201621123037qinyu\\WordCount_2\\test2.txt";
	String file3 = "D:\\soft-ware\\PersonalProject-Java\\201621123037qinyu\\WordCount_2\\test3.txt";
	String file4 = "D:\\soft-ware\\PersonalProject-Java\\201621123037qinyu\\WordCount_2\\test4.txt";
	String file5 = "D:\\soft-ware\\PersonalProject-Java\\201621123037qinyu\\WordCount_2\\test5.txt";
	
	
	@BeforeEach
	void setUp() throws Exception {
	}

	
	@Test
	void testCountChars() throws IOException {
		File file=new File();
		ArrayList<String> line1=new ArrayList<>();
		ArrayList<String> line2=new ArrayList<>();
		ArrayList<String> line3=new ArrayList<>();
		ArrayList<String> line4=new ArrayList<>();
		
		line1=file.readfile(file1);
		line2=file.readfile(file2);
		line3=file.readfile(file3);
		line4=file.readfile(file4);
		
		Count count1=new Count(line1);
		Count count2=new Count(line2);
		Count count3=new Count(line3);
		Count count4=new Count(line4);
		
		int CountChars1=count1.CountChars();
		int CountChars2=count2.CountChars();
		int CountChars3=count3.CountChars();
		int CountChars4=count4.CountChars();
		
	//	assertEquals(CountChars1,0);
		assertEquals(CountChars2,24);
		assertEquals(CountChars3,56);
		assertEquals(CountChars4,200);
		
	}

	@Test
	void testCountWords() throws IOException {
		File file=new File();
		ArrayList<String> line1=new ArrayList<>();
		ArrayList<String> line2=new ArrayList<>();
		ArrayList<String> line3=new ArrayList<>();
		ArrayList<String> line4=new ArrayList<>();
		
		line1=file.readfile(file1);
		line2=file.readfile(file2);
		line3=file.readfile(file3);
		line4=file.readfile(file4);
		
		Count count1=new Count(line1);
		Count count2=new Count(line2);
		Count count3=new Count(line3);
		Count count4=new Count(line4);
		
		int CountWords1=count1.CountWords();
		int CountWords2=count2.CountWords();
		int CountWords3=count3.CountWords();
		int CountWords4=count4.CountWords();
		
		//assertEquals(CountWords1,5);
		assertEquals(CountWords2,1);
		assertEquals(CountWords3,9);
		assertEquals(CountWords4,27);
	}

	@Test
	void testCountLine() throws IOException {
		File file=new File();
		ArrayList<String> line1=new ArrayList<>();
		ArrayList<String> line2=new ArrayList<>();
		ArrayList<String> line3=new ArrayList<>();
		ArrayList<String> line4=new ArrayList<>();
		
		line1=file.readfile(file1);
		line2=file.readfile(file2);
		line3=file.readfile(file3);
		line4=file.readfile(file4);
		
		Count count1=new Count(line1);
		Count count2=new Count(line2);
		Count count3=new Count(line3);
		Count count4=new Count(line4);
		
		int CountLine1=count1.CountLine();
		int CountLine2=count2.CountLine();
		int CountLine3=count3.CountLine();
		int CountLine4=count4.CountLine();
		
		//assertEquals(CountLine1,5);
		assertEquals(CountLine2,6);
		assertEquals(CountLine3,4);
		assertEquals(CountLine4,12);
	}

	@Test
	void testWordTop() throws IOException {
		/*File file=new File();
		ArrayList<String> line=new ArrayList<>();
		int n = 10;//-n参数设定输出的单词数量
		line=file.readfile(file1);
		
		Count count=new Count(line);
		int CountWords=count.CountWords();
		
		int WordTop=count.WordTop(n,CountWords).size();
		
		assertEquals(WordTop,10);*/
		
	}

	@Test
	void testCountPhrase() throws IOException {

	
		
/*
		File file=new File();		
		ArrayList<String> line=new ArrayList<>();
		line=file.readfile(file4);
		//System.out.println(line);
		Count count=new Count(line);
		Map<String,Integer> CountPhrase=count.CountPhrase(4);*/
		
		File file=new File();		
		ArrayList<String> line=new ArrayList<>();
		line=file.readfile(file4);
		Count count=new Count(line);
		int CountChars=count.CountChars();
		int CountWords=count.CountWords();
		int CountLine=count.CountLine();
		//ArrayList<Entry<String, Integer>> wordtop=count.WordTop(n,CountWords);
		Map<String,Integer> CountPhrase=count.CountPhrase(4);
		
		/*Map<String,Integer> w1 = new HashMap<String,Integer>();
		Map<String,Integer> w2 = new HashMap<String,Integer>();*/
		Map<String,Integer> w3 = new HashMap<String,Integer>();
	//	Map<String,Integer> w4 = new HashMap<String,Integer>();
	
		w3.put("dreams will come true", 1);
		w3.put("live through your pain", 1);
		w3.put("trying times will pass", 1);
		w3.put("your dreams will come", 1);
		
		System.out.println("CountPhrase");
		System.out.println(CountPhrase);
		
		System.out.println("w3");
		System.out.println(w3);
		
		assertEquals(CountPhrase, w3);
		
	}

}
